<script language="javascript">
	var measuretree = {
		view: {
			showLine: false
		},
		edit: {
			drag: {
				autoExpandTrigger: true,
				prev: dropPrevLevel,
				inner: dropInnerLevel,
				next: dropNextLevel
			},
			enable: true,
			showRemoveBtn: true,
			showRenameBtn: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			beforeRemove: doRemoveLevel,
			onDblClick: measure_doDblClick,
			beforeCheck: zTreeBeforeCheck,
			onClick: zTreeOnClick,
			
			onRemove: zTreeOnRemove
		}

	};
	function zTreeBeforeRemove(treeId, treeNode) {
		return true;
	}	
	function zTreeBeforeCheck(treeId, treeNode) {
	    return true;
	};
	/**
	* delete 键 删除事件
	*/
	function zTreeOnRemove(event, treeId, treeNode) {
		return false;
	}
	/**
	* shift 键选中事件
	*/
	function zTreeOnClick(event, treeId, treeNode) {
		var treeObj = $.fn.zTree.getZTreeObj(treeId);
		var index = treeObj.getNodeIndex(treeNode); //获取到当前节点的序列
		var ind_measure = $("#ind_measure").val(); //获取到上一次选中的节点
		document.getElementById('ind_measure').value=index;  //将本次的获取的节点存入隐藏域中
		if(event.shiftKey){
			if(ind_measure != null && ind_measure != undefined && ind_measure != ""){
				var nodes =  treeObj.getNodes();
				for(var i = 0 ; i < nodes.length ; i ++){
					var node = treeObj.getNodeByTId(nodes[i].tId); 
					treeObj.cancelSelectedNode(node);
					if((index <= i && i <= ind_measure) || (index >= i && i  >= ind_measure)){
						treeObj.selectNode(node,true);
					}
				}
			}
			treeObj.selectNode(treeNode,true);
		}
	};
	
	function dropPrevLevel(treeId, nodes, targetNode) {
		var pNode = targetNode.getParentNode();
		if (pNode && pNode.dropInner === false) {
			return false;
		} else {
			for (var i=0,l=curDragNodes.length; i<l; i++) {
				var curPNode = curDragNodes[i].getParentNode();
				if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
					return false;
				}
			}
		}
		return true;
	}

	function dropInnerLevel(treeId, nodes, targetNode) {
		if (targetNode && targetNode.dropInner === false) {
			return false;
		} else {
			for (var i=0,l=curDragNodes.length; i<l; i++) {
				if (!targetNode && curDragNodes[i].dropRoot === false) {
					return false;
				} else if (curDragNodes[i].parentTId && curDragNodes[i].getParentNode() !== targetNode && curDragNodes[i].getParentNode().childOuter === false) {
					return false;
				}
			}
		}
		return true;
	}
	function dropNextLevel(treeId, nodes, targetNode) {
		var pNode = targetNode.getParentNode();
		if (pNode && pNode.dropInner === false) {
			return false;
		} else {
			for (var i=0,l=curDragNodes.length; i<l; i++) {
				var curPNode = curDragNodes[i].getParentNode();
				if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
					return false;
				}
			}
		}
		return true;
	}
	/**
	 *	删除 level	
	 **/
	function doRemoveLevel(e,treeNode) {
		var lid = treeNode.lid ;	
		art.confirm('您确定要删除此指标吗？' , 
			function(){
				//loadURL('/${orgi}/dm/cube/cubeauthlist/'+treeNode.cubeid+'.html','#auth');
				loadURL('/${orgi}/dm/cube/'+treeNode.cubeid+'/measuredelo/'+treeNode.lid+'.html' , "#measure_div" , null);
				
				
			} , function(){});
		return false;
	}

	/**
	 *	双击编辑	
	 **/
	function measure_doDblClick(e, treeId, treeNode) {
		$("#measureedit").show();
		$("#measureedit").attr("data-id",treeNode.lid);
		$("#measureedit").attr("href","/${orgi}/dm/cube/"+treeNode.cubeid+"/measureedit/"+treeNode.lid+".html");
		$("#measureedit").click();
		return !treeNode.isFirstNode;
	}



	var measure =[
		<#if measurelist??>
		<#list measurelist as measure>
			<#if measure_index != 0 >,</#if>{ id:${1000+measure_index} ,cubeid : "${measure.cubeid!''}", lid:"${measure.id!''}" , pId:0, name:"${measure.name!''}<#if measure.calculatedmember == true>（计算指标）</#if>" , icon:"/assets/images/ruler_triangle1.png", dropInner:false , click:"loadURLWithTip('/${orgi}/dm/cube/${measure.cubeid!''}/measureauth/${measure.id}.html','#auth',null,false)"}
		</#list>
		</#if>	
	];
	$("#measureZtree").keydown(function(event){
		alert(event.keyCode);
	});
	$().ready(function() {
		var measureZtree = $.fn.zTree.init($("#measureZtree"), measuretree, measure);
	});
	<#if result_msg??>alertMsg("${result_msg!''}");</#if>
</script>


	<div class="tableScrollWrap">
		<div class="ztree" id="measureZtree" style="height: 100%;"></div>
		<input type ="hidden" id = "ind_measure" value="" />
	</div>
	<i style="display:none;" data-toggle="ajax" id="measureedit" data-width="560" class="cbtn-icon-45" title="修改指标"></i>

